<?php
    $content    = 'company/product.php';
    $post_title     = '';
require_once TMP_SELL_PATH;
?>
<?php
$category = isset($_GET['cat_p'])?$_GET['cat_p']:$_GET['cat_id'];
$category_id = isset($_GET['cat_p'])?$_GET['cat_p']:$_GET['cat_id'];
$subcat = isset($_GET['cat_p'])?$_GET['cat_p']:'';
$qstring = "cat_p=".isset($_GET['cat_p'])."&amp;cat_id=".$subcat;
if(isset($_GET['cat_p']) && !isset($_GET['cat_id'])){
	$parent = $_GET['cat_p'];
	$qstring = "cat_p=$parent";
	$sql_1 = "SELECT id, parent_id FROM tblcategory WHERE parent_id = $parent";
	$result_1 = mysql_query($sql_1);
	$id = array();
	if(dbNumRows($result_1)){
	while($row_1 = mysql_fetch_assoc($result_1)){
		$id[] = $row_1['id'];
	}
	$category = implode(',',$id);
	}
}
?>


<?php
if(!empty($_GET["decode"]))
    {
    $de = $_GET["decode"];
    $de = rtrim($de, '/');
    $de = explode('/', $de);
        $wseller        = "com.`shorturl`='".$de[0]."'"; //line 852 in comment-funt.php
        $getseller      = new seller();
        $seller_all     = $getseller->sellers($wseller);
        $seller_row     = mysql_fetch_assoc($seller_all);
        $owner = $seller_row['user_id'];
    }
    //end for seller id

    if(!empty($_GET['color']))
        {
            $mixid = "AND mix.color_id='".$_GET['color']."'";
        }
    else if(!empty($_GET['size']))
        {
            $mixid = "AND mix.size_id='".$_GET['size']."'";
        }
    else if(!empty($_GET['brand']))
        {
            $mixid = "AND mix.brand_name='".$_GET['brand']."'";
        }
    else
        {
            $mixid ='';
    } 
    //end size , color and brand   
     	
		$rowsPerPage = isset($_GET['num'])?$_GET['num']:'12';
		$select = ("SELECT p.product_type, p.product_name, pic.product_id, pic.category_id, img.thumbnail,img.images, pip.price, pip.country_id,p.id,pip.pid
				FROM `tblproduct` AS p LEFT JOIN `tblimage` AS img ON p.id = img.product_id
				LEFT JOIN `tblproduct_in_pharmacy` AS pip ON p.id = pip.product_id 
				LEFT JOIN tblproduct_in_category AS pic ON p.id = pic.product_id
				INNER JOIN tbl_color_size AS mix ON mix.pid=p.id
				WHERE pic.category_id IN ($category) AND pip.status = 1 AND p.`owner`=$owner $mixid GROUP BY p.id ");
		$result     = mysql_query(getPagingQuery($select, $rowsPerPage));
		$pagingLink = getPagingLink($select, $rowsPerPage, $qstring);
?>
 <div style="margin-left:15px;">
		<div class="twelve columns">
            <div class="bo_eee radius1 ba_fff pad_10" style="margin-right: 15px; margin-bottom:15px;">
                <?php echo getCategoryName($category_id);?>
            </div>        
        </div>
</div>
	<?php
    if(!empty($subb))
        {
            $catid  = '&cat_id='.$subb;
        }
        if(!empty($seller_cat))
        {
            $seller_catp  = '&cat_p='.$seller_cat;
        }
	$i = 0;
		if(dbNumRows($result)>0){
		while($data=mysql_fetch_assoc($result)){
		$pharmacy=mysql_query("SELECT COUNT(DISTINCT pharmacy_id) AS pid
		FROM tblproduct_in_pharmacy WHERE product_id=".$data['id']." AND country_id=".$data['country_id']);
		
		$price=mysql_query("SELECT price FROM tblproduct_in_pharmacy WHERE product_id=".$data['id']." ORDER BY price ASC LIMIT 0,1");
		$myprice=mysql_fetch_assoc($price);
		$price1=mysql_query("SELECT price FROM tblproduct_in_pharmacy WHERE product_id=".$data['id']." ORDER BY price DESC LIMIT 0,1");
		$myprice1=mysql_fetch_assoc($price1);
		if($i==0)
		{
		echo '';			
		}else{
		echo '';	
		}
		$i++;
	?>

<div style="margin-left:15px;">
    <div class="three columns">
        <div class="product-cat">
        <div class="image_por">
            <a href="<?php echo W_ROOT;?>/product/product_detail.php?product_id=<?php echo $data['id']?><?php if(!empty($seller_catp)) {echo $seller_catp;}?><?php if(!empty($catid)) {echo $catid;}?>" title="<?php echo $data['product_name'] ?>"><img src="<?php echo W_S_IMAGES_DIR.$data['thumbnail'] ?>" /></a>
        </div>         
        <div class="pro-title">
            <a href="<?php echo W_ROOT;?>/product/product_detail.php?product_id=<?php echo $data['id']?><?php if(!empty($seller_catp)) {echo $seller_catp;}?><?php if(!empty($catid)) {echo $catid;}?>" title="<?php echo $data['product_name'] ?>"><?php echo $data['product_name'] ?></a>
        </div>
        <div class="add-tocart">
            <a class="btn btn-mini btn-success" href="../libraryfiles/cart-functions.php?action=add&amp;pid=<?php echo $data['pid'] ?>"><i class="icon-shopping-cart icon-white"></i>add to cart</a>
        </div>
        <span class="price">
          <?php 
              if($myprice['price']==$myprice1['price'])
                    {
                        echo $myprice['price']."$";
                    }
                    else
                    {
                        echo $myprice['price'] .' - '. $myprice1['price']."$" ; 
                    }
          ?>
        </span>        
        </div>
    </div>
    <!--
    end six columns
    -->

</div>


    <?php  } 
		}else{
	?>

    <div style="margin-left:15px;">
		<div class="twelve columns">
            <div class="bo_eee radius1 ba_fff pad_10" style="margin-right: 15px; margin-bottom:15px;">
                <h3 align="center" style="text-align:center;"><!--No Product in --><?php echo $lang['NOPRODUCTALERT'];?><?php echo getCategoryName($category_id);?></h3>
            </div>
        </div>
  </div>

    <?php		
		}
	 ?>

<?php if(!empty($pagingLink))
{?>
    <div style="margin-left:15px;">
		<div class="twelve columns">
            <div class="bo_eee radius1 ba_fff pad_10" style="margin-right: 15px; margin-bottom:15px;">
			<div class="wp-pagenavi">
				<?php echo $pagingLink;?>
                <div class="clear"></div>
			</div>
            </div>
        </div>
  </div>
<?php
}
?>   